package com.zhuiYun.project.api.userAddress.mapper;

import com.zhuiYun.project.api.userAddress.entiy.UserAddress;
import org.apache.ibatis.annotations.Mapper;
import com.zhuiYun.project.common.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @ClassName UserAddressMapper
 * @Description 收货地址类
 * @Author 胡亮
 * @Date 2023年4月5日08:32:54
 **/
@Mapper
public interface UserAddressMapper extends BaseMapper<UserAddress> {
    /**
     * @Author 赵笛
     * @Description TODO 根据用户id查询收货地址
     * @Date 2023/4/6 11:09
     * @Return com.zhuiYun.project.common.response.CommonResult
     * @param userId
     */
    @Select("select * from user_address where user_id = #{userId} order by address_flag desc")
    List<UserAddress> getAddressList(@Param("userId") Integer userId);

    /**
     * @author lyp
     * @description 获取用户默认选中的地址
     * @date 2023/4/14 9:25
     * @param: userId
     * @return UserAddress
     */
    @Select("<script>SELECT * FROM user_address WHERE user_id = #{userId} AND address_flag = 1 LIMIT 1</script>")
    UserAddress getUserDefaultAddress(Integer userId);
}
